package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbSpecificationMapper;
import com.dongdongshop.mapper.TbSpecificationOptionMapper;
import com.dongdongshop.model.*;
import com.dongdongshop.service.SpecOptionService;
import com.dongdongshop.vo.BrandVo;
import com.dongdongshop.vo.SpecOptionVo;
import com.dongdongshop.vo.SpecVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class SpecOptionServiceImpl implements SpecOptionService {

    @Resource
    private TbSpecificationOptionMapper tbSpecificationOptionMapper;

    @Resource
    private TbSpecificationMapper tbSpecificationMapper;

    @Override
    public SpecOptionVo showecho(Long id) {
        TbSpecification tbSpecification = tbSpecificationMapper.selectByPrimaryKey(id);
        TbSpecificationOptionExample te = new TbSpecificationOptionExample();
        TbSpecificationOptionExample.Criteria criteria = te.createCriteria();
        criteria.andSpecIdEqualTo(id);
        List<TbSpecificationOption> tbSpecificationOptions = tbSpecificationOptionMapper.selectByExample(te);
        SpecOptionVo vo = new SpecOptionVo(tbSpecification.getId(),tbSpecification.getSpecName(),tbSpecificationOptions);
        return vo;
    }

    @Override
    public List<SpecVo> optionList(SpecVo specvo) {
        TbSpecificationExample example = new TbSpecificationExample();
        TbSpecificationExample.Criteria criteria = example.createCriteria();
        List<TbSpecification> option = tbSpecificationMapper.selectByExample(example);
        return option.stream().map(op ->{
            SpecVo vo1 = new SpecVo();
            BeanUtils.copyProperties(op,vo1);
            return vo1;
        }).collect(Collectors.toList());
    }
}
